﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public partial class ExpenseType
    {
        public override string ToString()
        {
            return this.Name;
        }
        public static IQueryable<ExpenseType> GetAll(DAL.DataAccessLayer dal)
        {
            DataAccessDataContext dc = dal.DataContext;

            return from t in dc.ExpenseTypes
                   select t;
        }

        public static ExpenseType Get(DAL.DataAccessLayer dal, Guid id)
        {
            DataAccessDataContext da = dal.DataContext;
            var query = from e in da.ExpenseTypes
                        where e.Id.Equals(id)
                        select e;
            if (query.Count<ExpenseType>() > 0)
                return query.First<ExpenseType>();
            return null;
        }

        public void Save(DAL.DataAccessLayer dal)
        {
            DataAccessDataContext dc = dal.DataContext;
            dc.ExpenseTypes.InsertOnSubmit(this);
            dc.SubmitChanges();

        }

        public static IQueryable<Template> GetTemplate(DAL.DataAccessLayer dal, Guid id)
        {
            DataAccessDataContext dc = dal.DataContext;
            return from t in dc.ExpenseTypes
                   where t.Id.Equals(id)
                   select t.Template;
        }
    }
}
